package com.epam.command.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.command.logic.Command;
import com.epam.command.logic.ManagerLogic;
import com.epam.entity.Hotel;
import com.epam.entity.Hotel.Feeding;
import com.epam.util.ConfigurationManager;

public class CreateHotelCommand implements Command {

	
	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		String page = ConfigurationManager.getConfig(ConfigurationManager.OPERATION_SUCCESSFUL);
		
		String name = request.getParameter("name");
		int stars = Integer.parseInt(request.getParameter("stars"));
		boolean tv = Boolean.parseBoolean(request.getParameter("tv"));
		boolean conditioning = Boolean.parseBoolean(request
				.getParameter("conditioning"));
		Feeding feeding = Enum.valueOf(Hotel.Feeding.class,
				request.getParameter("feeding"));
		
		if (ManagerLogic.createHotel(name, stars, tv, conditioning, feeding)) {
			
			request.setAttribute("message", "Hotel created successfully");
			
		} else { 
			
			request.setAttribute("message", "Hotel already created");
			
		}
		
		return page;
		
	}
	
	

}
